<?php
$this->breadcrumbs=array(
	'Issues'=>array('index'),
	'Assign',
);

?>

<h1>Edit checker's page</h1>
<h4>Assign to edit the question and answer for editor and Check questions/answer which is submit by editor</h4>


<div class="list-sort">
<?php $form=$this->beginWidget('CActiveForm', array(
	'action'=>Yii::app()->createUrl($this->route),
	'method'=>'get',
  'htmlOptions'=>array('class'=>'form-horizontal'),
)); ?>
<?php echo CHtml::dropDownList('sort', '', $model->getListSort(),array('class'=>'sort'))?>
	<i class="icon-chevron-down"></i> 
	<input type="hidden" value="desc" name='sort_type'>
<?php $this->endWidget(); ?>
</div>

<a id="btnReload"  class="btn btn-primary"><i class="icon-refresh icon-white"></i> Refresh trang</a>



<div class="grid-view">
	<table border="1" class="items">
		<thead>
			<tr>
				<th>Issue</th>
				<th>Câu hỏi</th>
				<th>Trạng thái Q</th>
				<th>Editor 1</th>
				<th>Action</th>
				<th>Bài giải</th>
				<th>Trạng thái R</th>
				<th>Trạng thái A</th>
				<th>Editor 2</th>			
				<th>Action</th>
			</tr>
		</thead>
		<tbody>

		<?php
				$this->widget('zii.widgets.CListView', array(
				'id'=>'assign-issue-list',
				'dataProvider'=>$model->assign($ID),
				'pager'=>array
				(
					'firstPageLabel' => '&lt;&lt;',
			    'prevPageLabel'  => '&lt;',
			    'nextPageLabel'  => '&gt;',
			    'lastPageLabel'  => '&gt;&gt;',
					'header'=>'',
				),
				'emptyText'=>'Không có dữ liệu.',
				'itemView'=>'_view_assign_editor',
			)); 
		?>

	</tbody>
</table>	
</div>

<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->baseUrl; ?>/css/tables.css">
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->baseUrl; ?>/css/simplemodal/basic.css">
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl; ?>/js/countdown.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl; ?>/js/simplemodal/jquery.simplemodal.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl; ?>/js/simplemodal/basic.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl; ?>/js/simplemodal/popup.js"></script>

<script type="text/javascript">
	$(function() {
		$(".refresh").click(function() {
			console.log($(this));
			$(this).parent().children(".btn-success").removeAttr("disabled").removeClass("disabled");
			$(this).parent().children(".btn-inverse").removeAttr("disabled").removeClass("disabled");
		});
		$('.list-sort i').toggle(
				function() { 
					$('.list-sort i').attr('class','icon-chevron-up');
					$('.list-sort input:hidden').val('asc');
					$('.list-sort form').submit();
				}, 
				function() { 
					$('.list-sort i').attr('class','icon-chevron-down');
					$('.list-sort input:hidden').val('desc');
					$('.list-sort form').submit();
				}
			);
		
			$('.sort').change(function() {
				$('.list-sort form').submit();
			});
			
			$('.list-sort form').submit(function(){
				$.fn.yiiListView.update('assign-issue-list', {
					data: $(this).serialize()
				});
				return false;
			});


			// Refresh page by click on Refresh button
			$(document).ready(function() {
			
					setupRefresh();
					
			    $('#btnReload').click(function() {
			            location.reload();
			      });
			}); 

			// Auto refresh after  10 minutes.
			window.onload = setupRefresh;
	    function setupRefresh()
	    {
	        setInterval("refreshPage();",600000);
	    }
	    
	    function refreshBlock()
	    {
	       $('#block1').load("index.html");
	    }

	    function refreshPage() {
	        window.location = location.href;
	    }
				
});


function beforeAssign(issueID,num,status) {
	var ediorID = $("#issue_"+issueID+"_"+num).val();
	$.ajax({
		url: baseUrl + "/admin/issue/setAssignEditor",
		data: {issueID: issueID, ediorID: ediorID, status: status, num: num},
		type: "POST",//or GET
		success: function(data) {
			if(data=="success") {
				alert(data);
				$("#"+status+"_"+issueID+"_"+num).addClass("disabled").attr("disabled","disabled");
			}
		}
	});
}
</script>